package com.wanpinghui.wphlibrary.model.message.bean;

import com.wanpinghui.wphlibrary.model.oauth.UserInfoUtil;
import com.wanpinghui.wphlibrary.model.oauth.bean.UserBean;
import com.wanpinghui.wphlibrary.model.oauth.bean.UserInformation;
import com.yunshl.yunshllibrary.utils.TextUtil;

import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

/**
 * Created by xiongning on 17-12-1.
 */
@Table(name = "im_recent_msg")
public class RecentMsgBean {

    //指明字段,主键,是否自增长,约束(不能为空)
    @Column(name = "id", isId = true, autoGen = false, property = "NOT NULL")
    private String group_id;//组id

    @Column(name = "to_id")
    private String to_id;// 接收人

    @Column(name = "un_read_count")
    private int un_read_count;// 未读数量

    @Column(name = "message")
    private String message;// 消息内容

    @Column(name = "msg_type")
    private int msg_type;// 消息类型  1：新订单提醒、2：普通聊天、3：竞标成功提醒、4：客服

    @Column(name = "from_id")
    private String from_id;// 发送人

    @Column(name = "created_at")
    private long created_at;// 消息发送的时间戳

    public long getCreated_at() {
        return created_at;
    }

    public void setCreated_at(long created_at) {
        this.created_at = created_at;
    }

    public String getGroup_id() {
        return group_id;
    }

    public void setGroup_id(String group_id) {
        this.group_id = group_id;
    }

    public String getTo_id() {
        return to_id;
    }

    public void setTo_id(String to_id) {
        this.to_id = to_id;
    }

    public int getUn_read_count() {
        return un_read_count;
    }

    public void setUn_read_count(int un_read_count) {
        this.un_read_count = un_read_count;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getMsg_type() {
        return msg_type;
    }

    public void setMsg_type(int msg_type) {
        this.msg_type = msg_type;
    }

    public String getFrom_id() {
        return from_id;
    }

    public void setFrom_id(String from_id) {
        this.from_id = from_id;
    }

    private String name;

    private String url;

    private int no_read_num;

    private String content;

    private String time;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getNo_read_num() {
        return no_read_num;
    }

    public void setNo_read_num(int no_read_num) {
        this.no_read_num = no_read_num;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }


    public String getChatImId(){
        String chatImId=null;
        if(TextUtil.equals(getMyImId(),to_id))
            chatImId=from_id;
        if(TextUtil.equals(getMyImId(),from_id))
            chatImId=to_id;
        return chatImId;
    }

    public String getMyImId(){
        String myImId=null;
        UserBean ub= UserInfoUtil.getUserInfo();
        if(ub!=null){
            UserInformation uinf=ub.getUser();
            if(uinf!=null){
                myImId=ub.getUser().getId();
            }
        }
        return myImId;
    }
}
